/*
 * 广州云徙科技有限公司源代码，版权归广州云徙科技有限公司所有。
 * 
 * 项目名称 : yxs-gateway
 * 创建日期 : 2017年3月28日
 * 修改历史 : 
 *     1. [2017年3月28日]创建文件 by tan.wenjuan
 */
package com.project.ds;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import com.dtyunxi.ds.BaseMapper;
import com.project.ds.sqlprovider.ArticleMapperProvider;
import com.project.entity.atricle.Article;

/**
 * @author tan.wenjuan
 */
@Mapper
public interface ArticleMapper extends BaseMapper<Article> {
    @Select("select * from b_article where id = #{id}")
    public Article getById(Long id);
    
    @SelectProvider(type = ArticleMapperProvider.class, method = "getArticleListByCategoryId")
    public List<Article> getArticleListByCategoryId(@Param("categoryId")Long categoryId,int pageSize,int pageNo );
    
    @SelectProvider(type = ArticleMapperProvider.class, method = "getArticleListByLabelId")
    public List<Article> getArticleListByLabelId(@Param("labelId")Long labelId,int pageSize,int pageNo);
    
    @Select("select article_id,user_id from b_collection where article_id = #{id} and user_id = #{userId}")
    public Map<String,Object> getCollectionByUserId(@Param("id")Long id,@Param("userId")Long userId);
    
    @SelectProvider(type = ArticleMapperProvider.class, method = "getArticlePhotoList")
    public List<Map<String,Object>> getArticlePhotoList(@Param("categoryId")Long categoryId);
    
    @SelectProvider(type = ArticleMapperProvider.class, method = "getArticlePhotoListByLabelId")
    public List<Map<String,Object>> getArticlePhotoListByLabelId(@Param("labelId")Long labelId);
    
    @Insert("insert into b_collection(user_id,article_id,create_time) values(#{userId},#{articleId},now())")
    public int collectArticle(@Param("articleId")Long articleId,@Param("userId")Long userId);
    
    @Update("delete from b_collection where user_id=#{userId} and article_id=#{articleId}")
    public int cancelCollect(@Param("articleId")Long articleId,@Param("userId")Long userId);
    
    @Update("UPDATE b_article SET page_view = page_view+1 WHERE id = #{id}")
    void updatePageView(Long id);
    
    @SelectProvider(type = ArticleMapperProvider.class, method = "getCollectionList")
    public List<Article> collectList(@Param("userId")Long userId,int pageSize,int pageNo );
    
    @Select("select count(1) from b_collection c WHERE c.user_id= #{userId}")
    public int collectCount(Long userId);
    
    @SelectProvider(type = ArticleMapperProvider.class, method = "getArticleListByTitle")
    public List<Article> getArticleListByTitle(String title,int pageSize,int pageNo );
    
    @Select("select count(1) from b_article where publish_status = 'P' and title like CONCAT('%',#{like},'%')")
    public int articleCount(String title);
}
